package org.ands.input;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.List;

public abstract class IInputHelper {
	
	/**
	 * Returns a string that was obtained from path
	 * provided (the node that this InputHelper wraps
	 * would have been set in constructor or reset
	 * with updateContent().
	 *
	 * @param path the path
	 * @return          		If successful, a string of content
	 * obtained from path of the
	 * node which this class wraps.
	 * @throws Exception 		If nothing retrieved
	 * @since     1.0
	 */
	public abstract List<String> contentListFromPath(
			final String path) 
					throws Exception ;
	
//	/** 
//	 * Changes what the concrete class wraps - specified by content string.
//	 * When the concrete class is constructed, a node is provided
//	 * to it.  When you want to change which node it wraps, you
//	 * provide this string of content which it uses to construct
//	 * a node of the type that it understands (e.g. json node or xml node)
//	 *
//	 * @param 	content			Content to update with.
//     * 
//	 * @throws Exception 		If nothing retrieved
//	 * @since     1.0
//     */
//	public abstract void updateContent(
//			final String content)
//				throws Exception;
//	
	/**
 * Returns a string that was obtained from the URI provided.
 *
 * @param uri the uri
 * @return          		If successful, a string of content
 * obtained from the URI provided.
 * @throws Exception 		If nothing retrieved
 * @since     1.0
 */
	public static String contentFromUri(
			final String uri) 
					throws Exception{
		
		URL url = new URL(uri);
		BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
		String inputLine = "";
		String stringFromUri = "";
        while ((inputLine = in.readLine()) != null){
        	stringFromUri += inputLine;
        }
        
    	in.close();
    	
    	if(stringFromUri.isEmpty()){
			throw new Exception("No string content obtained from uri ["+uri+"].");
		}
		
    	return stringFromUri;
		
	}

	/**
	 * Gets the look up node value.
	 *
	 * @param lookUpUri the look up uri
	 * @param treePath the tree path
	 * @return the look up node value
	 * @throws Exception the exception
	 */
	public abstract List<String> getLookUpNodeValue(String lookUpUri, String treePath)
			throws Exception;

};
